home *** CD-ROM | disk | FTP | other *** search
/ 17 Bit Software 6: Level 6 / 17 Bit - Level 6 (1998)(Epic Marketing)[!].iso / quartz / q1059.dms / q1059.adf / bsplit / sharfile < prev   
Text File  |  1993-08-30  |  3KB  |  139 lines

  1. #! /bin/sh
  2. # This file was wrapped with "dummyshar".  "sh" this file to extract.
  3. # Contents:  bsplit.c
  4. echo extracting 'bsplit.c'
  5. if test -f 'bsplit.c' -a -z "$1"; then echo Not overwriting 'bsplit.c'; else
  6. sed 's/^X//' << \EOF > 'bsplit.c'
  7. X/*
  8. X * bsplit.c - split binary files in manageable pieces.
  9. X * usage is exactly like the split program.
  10. X *
  11. X * This program was written from scratch, without looking at the
  12. X * sources of split.
  13. X *
  14. X * Copyright (C) 1988 P. Knoppers
  15. X *                    Bilderdijkhof 59
  16. X *                    2624 ZG  Delft
  17. X *                    The Netherlands
  18. X */
  19. X
  20. Xchar copy0[] = "Copyright (C) 1988 P. Knoppers";
  21. Xchar copy1[] = "Permission to use and distribute copies of this";
  22. Xchar copy2[] = "program WITH SOURCE is granted to anyone, provided";
  23. Xchar copy3[] = "that it is NOT CHANGED in any way.";
  24. X
  25. X#include <stdio.h>
  26. X#define DEFSIZE 50000
  27. X#define DEFPREFIX "x"
  28. X#define MAXNAME 200
  29. X
  30. Xchar   *malloc ();
  31. X
  32. Xmain (argc, argv)        /* bsplit - split binary file */
  33. Xchar   *argv[];
  34. X{
  35. X    char   *buf;
  36. X    char   *myname;
  37. X    int     bulksize = DEFSIZE;
  38. X    int     level;
  39. X    int     got;
  40. X    int     fno = 0;
  41. X    char    outfname[MAXNAME + 1];
  42. X    char    outbase[MAXNAME + 3];
  43. X    int     foundinname = 0;
  44. X    FILE * infile = stdin;
  45. X    FILE * outfile;
  46. X
  47. X    myname = *argv;
  48. X    strcpy (outbase, DEFPREFIX);
  49. X    while (--argc > 0)
  50. X    {
  51. X    argv++;
  52. X    if ((*argv)[0] == '-')
  53. X    {
  54. X        if ((*argv)[1] == '\0')
  55. X        {
  56. X        if (foundinname != 0)
  57. X        {
  58. X            fprintf (stderr,
  59. X                "usage: %s [-size] [file [prefix]]\n",
  60. X                myname);
  61. X            exit (1);
  62. X        }
  63. X        foundinname++;
  64. X        }
  65. X        else
  66. X        if (sscanf (*argv, "-%d", &bulksize) != 1)
  67. X        {
  68. X            fprintf (stderr,
  69. X                "usage: %s [-size] [file [prefix]]\n",
  70. X                myname);
  71. X            exit (1);
  72. X        }
  73. X    }
  74. X    else
  75. X        if (foundinname != 0)
  76. X        {
  77. X        if (strlen (*argv) > MAXNAME)
  78. X        {
  79. X            fprintf (stderr, "%s: prefix too long\n",
  80. X                myname);
  81. X            exit (1);
  82. X        }
  83. X        strcpy (outbase, *argv);
  84. X        }
  85. X        else
  86. X        {
  87. X        if ((infile = fopen (*argv, "r")) == NULL)
  88. X        {
  89. X            fprintf (stderr, "%s: cannot open %s\n",
  90. X                myname, *argv);
  91. X            exit (1);
  92. X        }
  93. X        foundinname++;
  94. X        }
  95. X    }
  96. X
  97. X    if ((buf = malloc (bulksize)) == NULL)
  98. X    {
  99. X    fprintf (stderr, "%s: malloc failed\n", myname);
  100. X    exit (1);
  101. X    }
  102. X    level = 0;
  103. X    while (1)
  104. X    {
  105. X    got = read (fileno (infile), &buf[level], bulksize - level);
  106. X    level += got;
  107. X    if ((level < bulksize) && (got > 0))
  108. X        continue;
  109. X    if ((level == bulksize) || ((got == 0) && (level > 0)))
  110. X    {
  111. X        sprintf (outfname, "%s%c%c", outbase, fno / 26 + 'a',
  112. X            fno % 26 + 'a');
  113. X        if ((outfile = fopen (outfname, "w")) == NULL)
  114. X        {
  115. X        fprintf (stderr, "%s: cannot create %s\n", myname,
  116. X            outfname);
  117. X        exit (1);
  118. X        }
  119. X        if (write (fileno (outfile), buf, level) != level)
  120. X        {
  121. X        fprintf (stderr, "%s: write failed\n", myname);
  122. X        exit (1);
  123. X        }
  124. X        fclose (outfile);
  125. X        level = 0;
  126. X        fno++;
  127. X    }
  128. X    if (got == 0)
  129. X        break;
  130. X    }
  131. X}
  132. EOF
  133. chars=`wc -c < 'bsplit.c'`
  134. if test $chars !=    2804; then echo 'bsplit.c' is $chars characters, should be    2804 characters!; fi
  135. fi
  136. exit 0
  137.  
  138.  
  139.